<!doctype html>
<html>
<head>
	<meta charset="utf-8"><meta name="format-detection" content="telephone=no">
	<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
	<link rel="stylesheet" type="text/css" href="../../lib/css/skin.css"/>
</head>
<body>

<div id="root" class="root">

	<div class="app_warp">
		<div class="app_main cover_position"
		     style="background:#333 url(../../res/ad/cover_0.png)center;background-size: cover">
			<a id="close_cover_position" href="javascript:;">
				<span>4秒后关闭</span>
			</a>
		</div>
	</div>

</div>

<script>
	var isOpenIng = false,
		imageclip = function (name) {},
		timer = new Date().getTime(),
		openHome = function (status, newData, data) {

			if (!data) {
				data = appData;
			}

			if (newData === true) {

				for (var i in data) {
					if(i==='udb'){
						console.log('=====================');
						console.log(JSON.stringify(data[i]));
						console.log('=====================');
					}
					if (data[i] === null) {
						data[i] = appData[i]
					}
					_$.db.set({
						key: i,
						val: data[i]
					})
				}
				openHome(false, false);

			}else if (status === true) {
				if (isOpenIng !== false) {
					clearTimeout(isOpenIng);
				}
				api.openWin({
					name: 'index',
					url: './index.html',
					delay: 500
				});
			} else {
				isOpenIng = setTimeout(function () {
					openHome(true, false);
				}, 4500 - (new Date().getTime() - timer));
			}

		},

		appready = function () {
			_$.sleep(function () {
				api.removeLaunchView({
					animation: {
						type: 'fade',
						duration: 500
					}
				});
			}, 1500);
			setInterval(function(){
				_$.ajax({
					interface: 'getAppData',
					call: function (data) {
						for (var i in data) {
							if(i==='udb'){
								console.log('=====================');
								console.log(JSON.stringify(data[i]));
								console.log('=====================');
							}
							if (data[i] === null) {
								data[i] = appData[i]
							}
							_$.db.set({
								key: i,
								val: data[i]
							})
						}
					}
				})
			},300000)
			_$.ajax({
				interface: 'getAppData',
				call: function (data) {
					if (data.status === 200) {
						openHome(false, true, data.data);
					} else {
						openHome(false, false);
					}
				}
			})
			var coverPositionTimer = 5,
				coverPositionStatus = setInterval(function () {
					if (coverPositionTimer > 0) {
						coverPositionTimer = coverPositionTimer - 1;
					} else {
						clearInterval(coverPositionStatus);
					}
					$('#close_cover_position').html("<span> " + coverPositionTimer + "秒后关闭</span>");
				}, 1000);
			$('#close_cover_position').on('click', function () {
				clearInterval(coverPositionStatus);
				openHome(true, false);
			})
		};

</script>
<script src="../../lib/js/config.js"></script>
<script src="../../lib/js/data.js"></script>
<script src="../../lib/js/jquery.js"></script>
<script src="../../lib/js/common.js"></script>
</body>
</html>